#include <string.h>
#include <stdio.h>
#include "aliyun_iot_common_datatype.h"
#include "aliyun_iot_mqtt_nettype.h"
#include "aliyun_iot_platform_timer.h"
#include "aliyun_iot_common_log.h"
#include "aliyun_iot_platform_uart.h"
#include "aliyun_iot_platform_network.h"



INT32 aliyun_iot_mqtt_net_connect(INT8 *pHost, INT8 *pPort)
{
		INT32	ret;
		
		ret =  aliyun_iot_network_create(pHost,pPort,IOT_NET_PROTOCOL_TCP);
		if (ret >= 0)
				return 0;
		else
				return -1;
}


//+IPD,<len>:<data>
INT32 aliyun_iot_mqtt_nettype_read(Network *pNet, UINT8 *pRecvBuffer, INT32 recvBufferlen, INT32 timeOutMs)
{
		aliyun_iot_network_settimeout(NULL,timeOutMs,IOT_NET_TRANS_RECV);
		return aliyun_iot_network_recv(NULL, (unsigned char *)pRecvBuffer, recvBufferlen,NULL);
}


INT32 aliyun_iot_mqtt_nettype_write(Network *pNet, UINT8 *pSendBuffer, INT32 sendBufferlen, INT32 timeOutMs)
{
		aliyun_iot_network_settimeout(NULL,timeOutMs,IOT_NET_TRANS_SEND);
		return aliyun_iot_network_send(NULL, (unsigned char *)pSendBuffer, sendBufferlen,NULL);
}

INT32 aliyun_iot_mqtt_nettype_connect(Network *pNet)
{
	return aliyun_iot_mqtt_net_connect(pNet->connectparams.pHostAddress, pNet->connectparams.pHostPort);
}

void aliyun_iot_mqtt_nettype_disconnect(Network *pNet)
{
	
		aliyun_iot_network_close(NULL);
}


